package com.nan.buy.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.nan.buy.common.SessionConstants;
import com.nan.buy.model.Notice;
import com.nan.buy.service.NoticeService;
/**
 * 公告信息
 * @author 孙楠楠
 *
 */
@Controller
@RequestMapping("notice")
public class NoticeController {

	@Resource
	private NoticeService noticeService;
	
	@RequestMapping("notice")
	public String noticeList(){
		return 	"admin/notice";
	}
	/*
	 * 查询所有公告信息
	 */
	@RequestMapping("search")
	@ResponseBody
	public List<Notice> searchNotices(){
		return noticeService.searchNotices();
	}
	
	/*
	 * 删除公告信息
	 */
	@RequestMapping("del")
	@ResponseBody
	public Object delNotice(String nId){
		int msg=noticeService.deleteByPrimaryKey(nId);
		return (msg != 0) ? true :false;
	}
	
	/*
	 * 修改公告信息
	 */
	@RequestMapping("update")
	@ResponseBody
	public Object updateNotice(Notice notice){
		int msg= noticeService.updateNotice(notice);
		return (msg != 0) ? true :false;
	}
	
	/*
	 * 添加公告信息
	 */
	@RequestMapping("add")
	@ResponseBody
	public Object addNotice(Notice notice,HttpSession httpSession){
		notice.setnAdmin((String) httpSession.getAttribute(SessionConstants.SESSION_LOGIN));
		int msg= noticeService.addNotice(notice);
		return (msg != 0) ? true :false;
	}
}
